/*
  luredis connector v1.0
  luredis provide a LUA API that allows interaction with redis server.
  Based on: hiredis, the offical C API to redis server.
  BSD license.
  Date: 08/29/12
  (C) minhnt@live.com

  How to use luredis in LUA?
  [1] Create a new connection: c = luredis.new_connection("host",port)
      If the connection cannot be established, the app will exit.
  [2] Send a command to redis server. luredis.sendCommand(c,<command>)
      The returned values are a tuple of (status,result)
      Please check the status before proceed.
      For redis SET command: the status OK is 5.
      For redis GET command:
            the status 1 is for string, 2 for array and 3 for integer.
*/

#ifndef LUREDIS_H
#define LUREDIS_H

extern "C" {
#include "hiredis/hiredis.h"
}
#include "l_utility.hpp"

//#define DEBUG_LUREDIS


namespace http {
    namespace server3 {

typedef redisContext* redisContextPtr;
int register_luredis (lua_State *L);

static inline void l_set_wq_buf(lua_State *L, sds str) {
    lua_getglobal(L,__WEBQUEUE_TABLE); // push table t on stack
    lua_pushlightuserdata(L,str); // push value v on stack
    lua_setfield(L,-2,__WEBQUEUE_BUFFER);
    lua_pop(L,1); // pop table
}

static inline sds l_get_wq_buf(lua_State* L){
    sds str;
    lua_getglobal(L,__WEBQUEUE_TABLE); // push table t on stack
    lua_getfield(L,-1,__WEBQUEUE_BUFFER);
    str = (sds)lua_touserdata(L,-1); // value is on top
    lua_pop(L,2); // pop table and value
    return str;
}

}
}


#endif // LUREDIS_H
